package com.test3;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/****
 * 创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待
 *
 */
public class FixedThreadPoolTest {
   public static void main(String[] args) {
			final ExecutorService newCachedThreadPool = Executors.newFixedThreadPool(3);

			for (int i = 0; i < 10; i++) {
				final int index = i;
				newCachedThreadPool.execute(new Runnable() {
					public void run() {
						try {
							Thread.sleep(1000);
						} catch (Exception e) {
						}
						System.out.println("i:" + index);
					}
				});
			}
}
}
